<template>
    <div class="form page">
        <formHeader :title="'添加商品'"></formHeader>
        <div class="con">
            <div class="items">
                <div class="item picker">
                    <div class="title"><div>*</div>类目</div>
                    <div class="select" @click="showTypePicker">
                        {{this.typeValue}}
                        <i class="cubeic-arrow arrow-icon"></i>
                    </div>
                </div>

                <div class="item upload">
                    <div class="cell">
                        <div class="title"><div>*</div>上传商品缩略图(尺寸:400*400):</div>
                        <imageUpload class="img" v-model="goods.img"></imageUpload>
                    </div>
                </div>
                <div class="item input">
                    <div class="title"><div>*</div>商品名称:</div>
                    <div class="field">
                        <input type="text" placeholder="请输入商品名称" v-model="goods.name"/>
                    </div>
                </div>
                <div class="item upload">
                    <div class="cell">
                        <div class="title"><div>*</div>上传商品主图(尺寸:800*800):</div>
                        <imageUpload class="img" v-model="goods.midImg"></imageUpload>
                    </div>
                </div>
                <div class="item textarea">
                    <div class="title"><div></div>商品描述:</div>
                    <div class="field">
                        <textarea placeholder="请输入商品描述" maxlength="60" v-model="goods.info"></textarea>
                    </div>
                </div>
                <div class="item upload">
                    <div class="cell">
                        <div class="title"><div>*</div>上传商品详情页(宽度750):</div>
                        <imageUpload class="img" v-model="goods.bigImg"></imageUpload>
                    </div>
                </div>
                <div class="item picker">
                    <div class="title"><div>*</div>请选择商品销售模式</div>
                    <div class="select" @click="showSalePicker">
                        {{this.saleMode}}
                        <i class="cubeic-arrow arrow-icon"></i>
                    </div>
                </div>
<!--                <div class="item upload">-->
<!--                    <div class="cell">-->
<!--                        <div class="title"><div></div>上传商品分享图:</div>-->
<!--                        <imageUpload class="img" v-model="goods.postImg"></imageUpload>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="item textarea">
                    <div class="title"><div></div>分享描述:</div>
                    <div class="field">
                        <textarea placeholder="请输入商品分享描述" maxlength="60" v-model="goods.title"></textarea>
                    </div>
                </div>
<!--                <div class="item input">-->
<!--                    <div class="title"><div>*</div>活动名称</div>-->
<!--                    <div class="field">-->
<!--                        <input type="text" placeholder="请输入活动名称" v-model="saleTypeInfoEntity.name"/>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="item picker">
                    <div class="title"><div></div>产品分享信息</div>
                    <div class="select" @click="showSharePicker">
                        {{shareValue||''}}
                        <i class="cubeic-arrow arrow-icon"></i>
                    </div>
                </div>
                <div class="item input" v-if="shareIndex===0">
                    <div class="title"><div></div>优惠描述</div>
                    <div class="field">
                        <input type="text" placeholder="优惠描述四字以内" v-model="goods.discountInfo" maxlength="4"/>
                    </div>
                </div>
                <div class="item input" v-if="shareIndex===0">
                    <div class="title"><div></div>优惠价格</div>
                    <div class="field">
                        <input type="text" placeholder="优惠价格三位数以内" v-model="goods.discountPrice" maxlength="4" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"/>
                    </div>
                </div>
                <div class="item input" v-if="shareIndex===0">
                    <div class="title"><div></div>活动信息</div>
                    <div class="field">
                        <input type="text" placeholder="活动信息八字以内" v-model="goods.actInfo" maxlength="8"/>
                    </div>
                </div>
                <div class="item input" v-if="shareIndex===1">
                    <div class="title"><div></div>卖点主题</div>
                    <div class="field">
                        <input type="text" placeholder="卖点主题四字以内" v-model="goods.buyTheme" maxlength="4"/>
                    </div>
                </div>
                <div class="item input" v-if="shareIndex===1">
                    <div class="title"><div></div>卖点信息</div>
                    <div class="field">
                        <input type="text" placeholder="卖点信息八字以内" v-model="goods.buyInfo" maxlength="8"/>
                    </div>
                </div>


            </div>

            <div class="items">
                <div class="item picker">
                    <div class="title"><div>*</div>生产日期</div>
                    <div class="select" @click="selectDate">
                        {{this.createTime||'请选择生产日期'}}
                        <i class="cubeic-arrow arrow-icon"></i>
                    </div>
                </div>
                <div class="item input">
                    <div class="title"><div>*</div>保质期</div>
                    <div class="field">
                        <input type="text" placeholder="请输入保质期(例:18月)" v-model="goods.guaranty"/>
                    </div>
                </div>
            </div>

            <div class="items">
                <div class="item input">
                    <div class="title"><div>*</div>零售价</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.nowPrice"/>
                    </div>
                </div>
                <div class="item input">
                    <div class="title"><div></div>划线价</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.oldPrice"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.saleType==5">
                    <div class="title"><div>*</div>采购价</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.shopPrice"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.saleType==1">
                    <div class="title"><div>*</div>供货价</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.supplyPrice"/>
                    </div>
                </div>
                <div class="item input">
                    <div class="title"><div></div>库存</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.stock"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.saleType==2">
                    <div class="title"><div>*</div>限购数量</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="act.number"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.saleType==17">
                    <div class="title"><div></div>可使用清货券</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="saleTypeInfoEntity.maxClear"/>
                    </div>
                </div>
<!--                <div class="item input" v-show="goods.saleType==17">-->
<!--                    <div class="title"><div></div>赠送清货券</div>-->
<!--                    <div class="field">-->
<!--                        <input type="number" placeholder="请输入数值" v-model="saleTypeInfoEntity.clearReward"/>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="item input" v-show="goods.saleType!=17">
                    <div class="title"><div>*</div>店铺服务津贴(单位%)</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" value="5" disabled/>
<!--                        <input type="number" min="5" max="99" maxlength="4" @keyup="limitManager($event)" placeholder="请输入数值(单位%)" v-model="act.managerReward" disabled/>-->
                    </div>
                </div>
                <div class="item input" v-show="goods.saleType!=17&&goods.saleType!=1">
                    <div class="title"><div></div>分享奖励代金券 <span v-if="goods.saleType==5"> (最低{{((goods.shopPrice*100)/1000).toFixed(2)||'0'}})</span></div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="saleTypeInfoEntity.cashReward"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.saleType!=17&&goods.saleType!=1">
                    <div class="title"><div></div>分享赠送换购券 <span v-if="goods.saleType==5"> (最低{{((goods.shopPrice*100)/1000).toFixed(2)||'0'}})</span></div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="saleTypeInfoEntity.voucherReward"/>
                    </div>
                </div>
<!--                <div class="item input" v-show="goods.saleType!=5&&goods.saleType!=17">-->
<!--                    <div class="title"><div></div>分享赠送优惠券</div>-->
<!--                    <div class="field">-->
<!--                        <input type="number" placeholder="请输入数值" v-model="saleTypeInfoEntity.couponReward"/>-->
<!--                    </div>-->
<!--                </div>-->

                <div class="item input" v-show="goods.saleType!=5&&goods.saleType!=17&&goods.saleType!=1">
                    <div class="title"><div></div>可使用优惠券额度</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="saleTypeInfoEntity.maxCoupon"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.saleType!=17">
                    <div class="title"><div></div>区域服务津贴</div>
                    <div class="field third">
                        <input type="number" placeholder="省"  v-model="provincePresent" disabled/>‰
                        <input type="number" placeholder="市" v-model="cityPresent" disabled/>‰
                        <input type="number" placeholder="区" v-model="districtsPresent" disabled/>‰
                    </div>
                </div>
                <div class="item input">
                    <div class="title"><div></div>店铺结算金额</div>
                    <div class="field amount">
                        <input type="number" disabled :value="amount"/>
                    </div>
                </div>
            </div>

            <div class="items">
                <div class="item picker">
                    <div class="title"><div></div>配送方式</div>
                    <div class="select">
                        快递发货
                        <i class="cubeic-arrow arrow-icon"></i>
                    </div>
                </div>
                <div class="item picker">
                    <div class="title"><div></div>运费设置</div>
                    <div class="select" @click="showPicker('运费设置',logList)">
                        {{logList[goods.logType]?logList[goods.logType].text:''}}
                        <i class="cubeic-arrow arrow-icon"></i>
                    </div>
                </div>
                <div class="item picker" v-show="goods.logType==2">
                    <div class="title"><div></div>物流规则</div>
                    <div class="select" @click="showLogTemPicker()">
                        {{logTemValue||''}}
                        <i class="cubeic-arrow arrow-icon"></i>
                    </div>
                </div>
                <div class="item input" v-show="goods.logType==1">
                    <div class="title"><div></div>满免数量</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.fullNumber"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.logType==1">
                    <div class="title"><div></div>未满邮费</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.logFee"/>
                    </div>
                </div>
                <div class="item input" v-show="goods.logType==2">
                    <div class="title"><div></div>产品重量kg</div>
                    <div class="field">
                        <input type="number" placeholder="请输入数值" v-model="goods.weight"/>
                    </div>
                </div>
<!--                <div class="item input" v-show="goods.logType==2">-->
<!--                    <div class="title"><div></div>每箱数量</div>-->
<!--                    <div class="field">-->
<!--                        <input type="number" placeholder="请输入数值" v-model="goods.perBox"/>-->
<!--                    </div>-->
<!--                </div>-->
            </div>

            <div class="items">
                <div class="item input">
                    <div class="title"><div></div>品牌名称:</div>
                    <div class="field">
                        <input type="text" placeholder="请输入品牌名称" v-model="goodsTemp.brandName"/>
                    </div>
                </div>
                <div class="item input">
                    <div class="title"><div></div>品牌简介:</div>
                    <div class="field">
                        <input type="text" placeholder="请输入品牌简介" v-model="goodsTemp.brandInfo"/>
                    </div>
                </div>
            </div>

            <div class="items">
                <div class="item upload" v-if="mainType==60||mainType==47||mainType==48||mainType==415">
                    <div class="cell">
                        <div class="title"><div></div>生产企业卫生许可证:</div>
                        <imageUpload class="img" v-model="goodsTemp.companyhealthLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==47||mainType==61||mainType==55||mainType==46||mainType==415">
                    <div class="cell">
                        <div class="title"><div></div>生产许可证:</div>
                        <imageUpload class="img" v-model="goodsTemp.produceLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==47||mainType==61||mainType==55||mainType==46||mainType==415">
                    <div class="cell">
                        <div class="title"><div></div>经营许可证:</div>
                        <imageUpload class="img" v-model="goodsTemp.manageLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==42||mainType==47||mainType==55||mainType==46">
                    <div class="cell">
                        <div class="title"><div></div>备案登记:</div>
                        <imageUpload class="img" v-model="goodsTemp.recordTable"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType">
                    <div class="cell">
                        <div class="title"><div></div>销售授权书:</div>
                        <imageUpload class="img" v-model="goodsTemp.salesAuthorization"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==61||mainType==415">
                    <div class="cell">
                        <div class="title"><div></div>产品加工协议:</div>
                        <imageUpload class="img" v-model="goodsTemp.productAgreement"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60">
                    <div class="cell">
                        <div class="title"><div></div>保健食品GMP证书:</div>
                        <imageUpload class="img" v-model="goodsTemp.gmpLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType">
                    <div class="cell">
                        <div class="title"><div></div>商标注册证:</div>
                        <imageUpload class="img" v-model="goodsTemp.trademarkLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==54||mainType==44||mainType==48||mainType==58||mainType==42||mainType==46||mainType==52||mainType==53||mainType==57">
                    <div class="cell">
                        <div class="title"><div></div>成品检测报告:</div>
                        <imageUpload class="img" v-model="goodsTemp.goodsProve"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==41">
                    <div class="cell">
                        <div class="title"><div></div>非特殊用途化妆品备案:</div>
                        <imageUpload class="img" v-model="goodsTemp.recordTable"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==41||mainType==47||mainType==415">
                    <div class="cell">
                        <div class="title"><div></div>商品质量保证书:</div>
                        <imageUpload class="img" v-model="goodsTemp.qualityGuaranty"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==41||mainType==54||mainType==45">
                    <div class="cell">
                        <div class="title"><div></div>完整的销售授权:</div>
                        <imageUpload class="img" v-model="goodsTemp.salesAuthorization"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType">
                    <div class="cell">
                        <div class="title"><div></div>进口货物报关单复印件:</div>
                        <imageUpload class="img" v-model="goodsTemp.goodsDeclaration"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==44||mainType==55">
                    <div class="cell">
                        <div class="title"><div></div>入境货物检验检疫证明:</div>
                        <imageUpload class="img" v-model="goodsTemp.testProve"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==45||mainType==41||mainType==47||mainType==44">
                    <div class="cell">
                        <div class="title"><div></div>产品加工协议:</div>
                        <imageUpload class="img" v-model="goodsTemp.productAgreement"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==47||mainType==61||mainType==415">
                    <div class="cell">
                        <div class="title"><div></div>食品流通许可证:</div>
                        <imageUpload class="img" v-model="goodsTemp.circulateLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==47||mainType==41||mainType==45||mainType==415">
                    <div class="cell">
                        <div class="title"><div></div>产品检测报告复印件:</div>
                        <imageUpload class="img" v-model="goodsTemp.detectPhotocopy"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==41||mainType==45||mainType==55">
                    <div class="cell">
                        <div class="title"><div></div>产品清单:</div>
                        <imageUpload class="img" v-model="goodsTemp.productList"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60">
                    <div class="cell">
                        <div class="title"><div></div>进口保健食品批准证书(若经营进口货物需提供):</div>
                        <imageUpload class="img" v-model="goodsTemp.approveLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==46||mainType==55">
                    <div class="cell">
                        <div class="title"><div></div>委托加工协议:</div>
                        <imageUpload class="img" v-model="goodsTemp.entrustAgreement"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==41">
                    <div class="cell">
                        <div class="title"><div></div>化妆品生产企业卫生许可证:</div>
                        <imageUpload class="img" v-model="goodsTemp.companyhealthLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==41||mainType==58||mainType==42||mainType==55">
                    <div class="cell">
                        <div class="title"><div></div>全国工业生产许可证:</div>
                        <imageUpload class="img" v-model="goodsTemp.industryLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==45||mainType==44||mainType==48||mainType==58||mainType==42||mainType==55||mainType==43">
                    <div class="cell">
                        <div class="title"><div></div>CCC认证证书:</div>
                        <imageUpload class="img" v-model="goodsTemp.cccLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==61">
                    <div class="cell">
                        <div class="title"><div></div>动物防疫条件合格证、动物检验检疫证明、</div>
                        <div class="title"><div></div>农产品卫生检疫合格证明:</div>
                        <imageUpload class="img" v-model="goodsTemp.epidemicPrevention"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==61">
                    <div class="cell">
                        <div class="title"><div></div>产品检测报告:</div>
                        <imageUpload class="img" v-model="goodsTemp.detectPhotocopy"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60||mainType==47">
                    <div class="cell">
                        <div class="title"><div></div>品牌商的食品经营企业卫生许可证:</div>
                        <imageUpload class="img" v-model="goodsTemp.managehealthLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload" v-if="mainType==60">
                    <div class="cell">
                        <div class="title"><div></div>生产厂商的企业营业执照副本复印件(非生产厂商):</div>
                        <imageUpload class="img" v-model="goodsTemp.companyLicense"></imageUpload>
                    </div>
                </div>
                <div class="item upload">
                    <div class="cell">
                        <div class="title"><div></div>品牌方承诺书或授权书:</div>
                        <imageUpload class="img" v-model="goodsTemp.brandAuthorization"></imageUpload>
                    </div>
                </div>
            </div>

            <div class="check">
                <div class="btnBox">
                    <div class="join" @click="submit">放入仓库</div>
                    <div class="sell" @click="submit">上架出售</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import formHeader from '@/components/form-header'
    import imageUpload from '@/components/form-update/image-upload'
    import {getTypeList,submitGood,getFormData,editGoods,getLogTem} from '@/api/form'
    import {showError} from '@/toast'
    export default {
        name: "newForm",
        components:{formHeader,imageUpload},
        data(){
            return{
                typeValue:'请选择商品类目',
                saleMode:'',
                shopType:'',
                logList:[
                    {text:'包邮',value:0},
                    {text:'满免',value:1},
                    {text:'计重',value:2}
                ],
                saleType:[
                    {text:'分享有利',value:0},
                    {text:'代理有利',value:1},
                    {text:'新品体验',value:2},
                    {text:'门店采购',value:5},
                    {text:'清货',value:17}
                ],
                shareMsg:[
                    {text:'活动信息',value:0},
                    {text:'卖点信息',value:1},
                ],
                shareIndex:null,
                shareValue:null,
                provincePresent:null,
                cityPresent:null,
                districtsPresent:null,
                mainType:null,

                clickFlag:true,

                goods:{
                    logType:'',
                    saleType:0,
                    nowPrice:null,

                },
                act:{
                    number:null
                },
                saleTypeInfoEntity:  {
                    id: null,
                    goodsId: null,
                    transfer: null,
                    delivery: null,
                    point: null,
                    maxVoucher: null,
                    maxCoupon: null,
                    pointReward: null,
                    pointType: null,
                    couponReward: null,
                    couponType: null,
                    voucherReward: null,
                    voucherType: null,
                    cashReward: null,
                    cashType: null,
                    areaReward: null,
                    areaType: null,
                    managerReward: null,
                    managerType: null,
                    maxClear:null
                },
                types:[],
                createTime:'',
                typeList:[],
                goodsTemp: {
                    id: null,
                    userId: null,
                    goodsId: null,
                    brandname: null,
                    brandinfo: null,
                    brandBusinessLicense: null,
                    companyHealthLicense: null,
                    manageHealthLicense: null,
                    approveLicense: null,
                    produceLicense: null,
                    registerNotice: null,
                    manageLicense: null,
                    gmpLicense: null,
                    trademarkLicense: null,
                    productAgreement: null,
                    circulateLicense: null,
                    betweenCirculateLicense: null,
                    detectPhotocopy: null,
                    goodsDeclaration: null,
                    productList: null,
                    companyLicense: null,
                    entrustAgreement: null,
                    qualityGuaranty: null,
                    healthPhotocopy: null,
                    fiveTrademark: null,
                    recordTable: null,
                    epidemicPrevention: null,
                    industryLicense: null,
                    salesAuthorization: null,
                    testProve: null,
                    cccLicense: null,
                    goodsProve: null,
                    brandAuthorization: null
                },
                logTemList:[],
                logTemValue:null,
            }
        },
        computed:{
            amount (){
                let sum = 0
                if (this.goods.saleType==5){
                    sum = Number(this.goods.shopPrice)
                        - Number(this.goods.shopPrice*this.saleTypeInfoEntity.managerReward/100)
                        - Number(this.saleTypeInfoEntity.cashReward)
                        - Number(this.saleTypeInfoEntity.voucherReward)
                        - Number(this.goods.shopPrice*this.provincePresent/1000)
                        - Number(this.goods.shopPrice*this.cityPresent/1000)
                        - Number(this.goods.shopPrice*this.districtsPresent/1000)
                }else if (this.goods.saleType==0||this.goods.saleType==2) {
                    sum = Number(this.goods.nowPrice)
                        - Number(this.goods.nowPrice * this.saleTypeInfoEntity.managerReward / 100)
                        - Number(this.saleTypeInfoEntity.cashReward)
                        - Number(this.saleTypeInfoEntity.voucherReward)
                        - Number(this.saleTypeInfoEntity.maxCoupon)
                        - Number(this.goods.nowPrice * this.provincePresent / 1000)
                        - Number(this.goods.nowPrice * this.cityPresent / 1000)
                        - Number(this.goods.nowPrice * this.districtsPresent / 1000)
                }else if (this.goods.saleType==17){
                    console.log(this.goods.nowPrice)
                    console.log(this.saleTypeInfoEntity.maxClear)
                    sum = Number(this.goods.nowPrice)
                        - Number(this.saleTypeInfoEntity.maxClear)
                }else if (this.goods.saleType==1){
                    sum = Number(this.goods.supplyPrice)
                        - 0.1
                }else if (this.goods.saleType==2){
                    // sum =
                }
                if (!sum){
                    sum = 0
                }
                return sum.toFixed(2)
            }
        },
        activated() {
            if (this.$route.query.id){
                getFormData(this.$route.query.id).then(res=>{
                    console.log(res)
                    this.goods = res.data
                    if(res.extra.act){
                        this.act = res.extra.act
                    }
                    this.saleTypeInfoEntity = res.extra.saleTypeInfoEntity
                    this.types = res.extra.types[0]
                    this.mainType = res.extra.types[0][0]
                    this.goodsTemp = res.extra.goodsQualificationEntity

                    this.saleTypeInfoEntity.cashReward = this.saleTypeInfoEntity.cashReward?this.saleTypeInfoEntity.cashReward.split('_')[1]:null
                    this.saleTypeInfoEntity.voucherReward =this.saleTypeInfoEntity.voucherReward?this.saleTypeInfoEntity.voucherReward.split('_')[1]:null

                    let areaReward = this.saleTypeInfoEntity.areaReward?this.saleTypeInfoEntity.areaReward.split('_'):[null,null.null]
                    this.provincePresent = areaReward[0]
                    this.cityPresent = areaReward[1]
                    this.districtsPresent = areaReward[2]

                    this.saleType.forEach(obj=>{
                        if (obj.value==this.goods.saleType){
                            this.saleMode = obj.text
                        }
                    })
                    getLogTem().then(res=>{
                        this.logTemList = res.data.map(item=>{
                            if (this.goods.logTemId==item.id){
                                this.logTemValue = item.name

                            }
                            return {value:item.id,text:item.name}
                        })
                    })
                    this.saleTypeInfoEntity.managerReward=Number(this.saleTypeInfoEntity.managerReward*100).toFixed(2)

                    this.goodsTemp = res.extra.goodsQualificationEntity



                    this.createTime = this.goods.createTime.toString().split(' ')[0]

                    if (this.goods.discountInfo||this.goods.discountPrice||this.goods.saleTypeInfoEntityInfo){
                        this.shareValue = this.shareMsg[0].text
                        this.shareIndex = 0
                    }
                    if (this.goods.buyTheme||this.goods.buyInfo){
                        this.shareValue = this.shareMsg[1].text
                        this.shareIndex = 1
                    }
                })
            }

            if (!this.saleTypeInfoEntity.managerReward){
                this.saleTypeInfoEntity.managerReward = 5
            }

            this.provincePresent=1
            this.cityPresent=2
            this.districtsPresent=3

            if (!this.$route.query.id){
                getLogTem().then(res=>{
                    this.logTemList = res.data.map(item=>{
                        if (this.goods.logTemId==item.value){
                            this.logTemValue = item.text
                        }
                        return {value:item.id,text:item.name}
                    })
                })
            }

            getTypeList().then(res=>{
                let list = res.data.filter(item=>
                    item.children.length >0
                )
                list=list.map(obj=>{
                    this.$set( obj, 'value', obj.id)
                    this.$set( obj, 'text', obj.name)
                    obj.children=obj.children.map(item=>{
                        this.$set( item, 'value', item.id)
                        this.$set( item, 'text', item.name)
                        return item
                    })
                    return obj
                })
                this.typeList = list
                // console.log(this.types)
                if (this.types){
                    this.typeList.forEach((obj,index)=>{
                        if (obj.id==this.types[0]){
                            let name = obj.name
                            obj.children.forEach(item=>{
                                if (item.id==this.types[1]){
                                    this.typeValue = name+'/'+item.name
                                }
                            })
                        }
                    })
                }
            })
        },
        methods:{
            showLogTemPicker() {
                if (!this.LogTemPicker) {
                    this.LogTemPicker = this.$createPicker({
                        title: '运费模版',
                        data: [this.logTemList],
                        onSelect: this.selectlogTem
                    })
                }
                this.LogTemPicker.show()
            },
            selectlogTem(selectedVal, selectedIndex, selectedText){
                this.logTemValue = selectedText[0]
                this.goods.logTemId = selectedVal[0]
            },
            showTypePicker(){
                if (!this.cascadePicker){
                    this.cascadePicker = this.$createCascadePicker({
                        title: '商品分类',
                        data: this.typeList,
                        onSelect: this.selectType
                    })
                }
                this.cascadePicker.show()

            },
            selectType(selectedVal, selectedIndex, selectedText){
                this.typeValue = selectedText.join('/')
                this.types[0] = selectedVal[1]
                this.mainType = selectedVal[0]
            },
            selectDate(){
                if (!this.datePicker) {
                    let date = new Date()
                    // console.log(date)
                    this.datePicker = this.$createDatePicker({
                        title: '选择生产日期',
                        min: new Date(2008, 7, 8),
                        max: new Date(date.getFullYear(), date.getMonth(), date.getDay()),
                        value: new Date(),
                        onSelect: this.selectTime
                    })
                }
                this.datePicker.show()
            },
            selectTime(date, selectedVal, selectedText) {
                this.goods.createTime = selectedVal.join('-')+' 00:00:00'
                this.createTime = selectedVal.join('-')
            },
            showPicker(title,list) {
                if (!this.picker) {
                    this.picker = this.$createPicker({
                        title: title,
                        data: [list],
                        onSelect: this.selectHandle
                    })
                }
                this.picker.show()
            },
            selectHandle(selectedVal, selectedIndex, selectedText) {
                this.goods.logType = selectedVal[0]
            },
            showSalePicker(){
                if (!this.salePicker) {
                    this.salePicker = this.$createPicker({
                        title: '销售模式',
                        data: [this.saleType],
                        onSelect: this.saleSelect
                    })
                }
                this.salePicker.show()
            },
            saleSelect(selectedVal, selectedIndex, selectedText){
                this.saleMode = selectedText[0]
                this.goods.saleType = selectedVal[0]

            },
            showSharePicker() {
                if (!this.sharePicker) {
                    this.sharePicker = this.$createPicker({
                        title: '产品分享信息',
                        data: [this.shareMsg],
                        onSelect: this.selectShareHandle
                    })
                }
                this.sharePicker.show()
            },
            selectShareHandle(selectedVal, selectedIndex, selectedText) {
                this.shareIndex = selectedVal[0]
                this.shareValue = selectedText[0]
                if (selectedIndex==0){
                    this.goods.buyTheme = null
                    this.goods.buyInfo = null
                }
                if(selectedIndex==1){
                    this.goods.discountInfo = null
                    this.goods.discountPrice = null
                    this.goods.saleTypeInfoEntityInfo = null
                }
            },
            turn(path){
                this.$router.push({
                    path
                })
            },
            limitManager(e){
                if (e.target.value<5){
                    this.saleTypeInfoEntity.managerReward = 5
                }
            },
            submit(){
                // console.log(this.types)
                if (!this.clickFlag){
                    showError('请勿重复提交')
                    return
                }
                this.clickFlag = false
                setTimeout(()=>{
                    this.clickFlag = true
                },5000)
                if (!this.types[0]){
                    showError('请选择商品类目')
                    return
                }
                if (!this.goods.img){
                    showError('请上传商品缩略图')
                    return
                }
                if (!this.goods.name){
                    showError('请填写商品名称')
                    return
                }if (!this.goods.midImg){
                    showError('请上传商品主图')
                    return
                }if (!this.goods.bigImg){
                    showError('请上传商品详情页')
                    return
                }if (!this.goods.nowPrice){
                    showError('请填写商品零售价')
                    return
                }
                if (this.goods.logType===null) {
                    showError('请设置运费')
                    return
                }
                if(!this.goods.createTime){
                    showError('请添加生产日期')
                    return
                }
                if(!this.goods.guaranty){
                    showError('请添加保质期')
                    return
                }

                if(this.goods.saleType==5&&(this.saleTypeInfoEntity.cashReward*10<this.goods.shopPrice)){
                    showError('分享赠送代金券至少为采购价10%')
                    return
                }
                if(this.goods.saleType==5&&(this.saleTypeInfoEntity.voucherReward*10<this.goods.shopPrice)){
                    showError('分享赠送换购券至少为采购价10%')
                    return
                }
                if (this.goods.logType==2){
                    if (!this.goods.logTemId){
                        showError('请选择物流模版，若没有物流模版，请在电脑端添加')
                        return;
                    }
                }
                // if (!this.saleTypeInfoEntity.name){
                //     showError('请输入活动名称')
                //     return
                // }
                if (this.goods.saleType==17){
                    this.saleTypeInfoEntity.managerReward = null
                    this.saleTypeInfoEntity.cashReward = null
                    this.saleTypeInfoEntity.voucherReward= null
                    this.saleTypeInfoEntity.couponReward= null
                    this.saleTypeInfoEntity.maxCoupon= null
                    this.provincePresent= null
                    this.cityPresent= null
                    this.districtsPresent= null

                }

                this.saleTypeInfoEntity.managerReward = this.saleTypeInfoEntity.managerReward/100

                this.goods.img = this.goods.img.split(',')[0]
                // provincePresent:null,
                //     cityPresent:null,
                //     districtsPresent:null,
                if (!this.provincePresent){
                    this.provincePresent = 0
                }
                if (!this.cityPresent){
                    this.cityPresent = 0
                }
                if (!this.districtsPresent){
                    this.districtsPresent = 0
                }
                this.saleTypeInfoEntity.areaReward = this.provincePresent+'_'+this.cityPresent+'_'+this.districtsPresent
                this.saleTypeInfoEntity.cashReward = '0_'+this.saleTypeInfoEntity.cashReward
                this.saleTypeInfoEntity.voucherReward = '0_'+this.saleTypeInfoEntity.voucherReward

                if (!this.goods.id){
                    submitGood(this.goods,this.saleTypeInfoEntity,this.types,this.goods.createTime,this.goodsTemp,this.act).then(res=>{
                        if (this.goods.saleType!=17){
                            this.saleTypeInfoEntity.managerReward = 5
                        }
                        this.saleTypeInfoEntity.cashReward = this.saleTypeInfoEntity.cashReward?this.saleTypeInfoEntity.cashReward.split('_')[1]:null
                        this.saleTypeInfoEntity.voucherReward =this.saleTypeInfoEntity.voucherReward?this.saleTypeInfoEntity.voucherReward.split('_')[1]:null
                        this.$createDialog({
                            type: 'alert',
                            title: '我是标题',
                            content: '上传成功！',
                            confirm: this.turn('/shop'),
                            icon: 'cubeic-alert'
                        }).show()
                    })
                }else {
                    editGoods(this.goods,this.saleTypeInfoEntity,this.types,this.goods.createTime,this.goodsTemp,this.act).then(res=>{
                        if (this.goods.saleType!=17){
                            this.saleTypeInfoEntity.managerReward = 5
                        }
                        this.saleTypeInfoEntity.cashReward = this.saleTypeInfoEntity.cashReward?this.saleTypeInfoEntity.cashReward.split('_')[1]:null
                        this.saleTypeInfoEntity.voucherReward =this.saleTypeInfoEntity.voucherReward?this.saleTypeInfoEntity.voucherReward.split('_')[1]:null
                        this.$createDialog({
                            type: 'alert',
                            title: '我是标题',
                            content: '上传成功！',
                            confirm: this.turn('/shop'),
                            icon: 'cubeic-alert'
                        }).show()
                    })
                }
            }
        }
    }
</script>

<style scoped lang="stylus">
.form
    background-color $page-bg
    .con
        background-color: rgb(239,239,239)
        padding-top 47px
        .items
            margin-top 10px
            background-color #fff
            padding 0 15px
            .item
                height 47px
                display flex
                justify-content space-between
                align-items center
                border-bottom 1px solid #eee
                .title
                    display flex
                    color #333
                    font-size 15px
                    white-space nowrap
                    margin-right 10px
                    align-items center
                    div
                        width 5px
                        height 5px
                        color #00A398
                        font-size 11px
                        margin-right 4.5px
                .select
                    color #666
                    font-size 13px
                    text-align right
                    height 100%
                    display flex
                    align-items center
                    flex 1
                    justify-content flex-end
                    i
                        margin-top 2px
                .field
                    flex 1
                    display flex
                    align-items center
                    input
                        width 100%
                        font-size 14px
                        text-align right
                    input:focus {
                        outline: none
                    }
                    textarea
                        width 100%
                        height 60px
                        font-size 14px
                        resize none
                        margin-top 4px
                        border none
                    textarea:focus
                        outline: none
                .third
                    display flex
                    justify-content space-around
                    font-size 14px

                    input
                        border 1px solid #ccc
                        border-radius 2px
                        width 50px
                .amount
                    input
                        color #00a398
            .textarea
                height 87px
                .title
                    height calc(100% - 15px)
                    align-items flex-start
                    padding-top 15px
                .field
                    height 100%
            .upload
                height 127px
                .cell
                    margin-top 15px
                    height 100%
                .img
                    height 68px
                    margin-top 10px
            .tip
                color #999
                font-size 8px
                height 24px
                line-height 24px
        .check
            margin-top 33px
            background-color: #fff
            width 100%
            .btnBox
                margin 0 15px
                display flex
                justify-content space-between
                align-items center
                div
                    margin 4.5px 0
                    width 166px
                    height 40px
                    border 1px solid #e5e5e5
                    border-radius 3px
                    text-align center
                    line-height 40px
                    font-size 15px
                .join
                    color #333
                    background-color: #f8f8f8
                .sell
                    background-color #00a398
                    color #fff

</style>